/*
 * Created by SharpDevelop.
 * User: MyWife
 * Date: 27/01/10
 * Time: 1:27 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using popLib;
using System.Threading;

namespace StartupManager
{
	/// <summary>
	/// Description of Startup.
	/// </summary>
	public partial class Startup : Form
	{
		public Startup()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			
		}
		
		void Dowait( object obj ){			
			double counter = 1;
			double seconds =  Convert.ToDouble( (int)obj * 10 );
			
			while( counter <= seconds ){
				viewProgressBar( "Start next application in next ", Convert.ToInt16( (counter/seconds)*100), pbr_wait  );
				counter++;
				Thread.Sleep(100);
			}
		}
		
		
		void ActionEvent(object sender, EventArgs e)
		{
			switch( ((Button)sender).Text ){
				case "Cancel": break;
				case "Pause": break;
				case "Resume": break;
				case "Stop": break;
				case "Manual": break;				
			}
			Thread a = new Thread(Dowait);
			a.IsBackground = true;
			a.Start(5);
		}
		
		void viewProgressBar( string text, int percent, ProgressBar pgbar ){
			ThreadStart ts = delegate{
				pgbar.Value = percent > 100 ? 100: percent;
                string content = (StringLib.isValid(text) ? text + " - " + percent : percent.ToString()) + "%";
                using (Graphics gr = pgbar.CreateGraphics())
                {
                    gr.DrawString(content,
                        SystemFonts.DefaultFont,
                        Brushes.Black,
                        new PointF(
                            pgbar.Width / 2 - (gr.MeasureString(content, SystemFonts.DefaultFont).Width / 2.0F),
                            pgbar.Height / 2 - (gr.MeasureString(content, SystemFonts.DefaultFont).Height / 2.0F)
                        )
                   );
                }
			};
			this.Invoke( ts );			
		}
	}
}
